<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Open a connection/database</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.dbx-compare.html">dbx_compare</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.dbx-error.html">dbx_error</a></div>
 <div class="up"><a href="ref.dbx.html">dbx 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.dbx-connect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">dbx_connect</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5 &lt;= 5.0.5, PECL dbx &gt;= 1.1.0)</p><p class="refpurpose"><span class="refname">dbx_connect</span> &mdash; <span class="dc-title">Open a connection/database</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.dbx-connect-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">object</span> <span class="methodname"><strong>dbx_connect</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$module</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$host</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$database</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$username</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$password</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$persistent</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   Opens a connection to a database.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.dbx-connect-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">module</code></em></dt>

     <dd>

      <p class="para">
       The <em><code class="parameter">module</code></em> parameter can be either a string or a
       constant, though the latter form is preferred. The possible values are 
       given below, but keep in mind that they only work if the module is 
       actually loaded.
      </p>
      <p class="para">
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
          <strong><code>DBX_MYSQL</code></strong> or <em>&quot;mysql&quot;</em>
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>DBX_ODBC</code></strong> or <em>&quot;odbc&quot;</em>
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>DBX_PGSQL</code></strong> or <em>&quot;pgsql&quot;</em>
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>DBX_MSSQL</code></strong> or <em>&quot;mssql&quot;</em>
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>DBX_FBSQL</code></strong> or <em>&quot;fbsql&quot;</em>
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>DBX_SYBASECT</code></strong> or <em>&quot;sybase_ct&quot;</em>
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>DBX_OCI8</code></strong> or <em>&quot;oci8&quot;</em>
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>DBX_SQLITE</code></strong> or <em>&quot;sqlite&quot;</em>
         </span>
        </li>
       </ul>
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">host</code></em></dt>

     <dd>

      <p class="para">
       The SQL server host
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">database</code></em></dt>

     <dd>

      <p class="para">
       The database name
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">username</code></em></dt>

     <dd>

      <p class="para">
       The username
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">password</code></em></dt>

     <dd>

      <p class="para">
       The password
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">persistent</code></em></dt>

     <dd>

      <p class="para">
       The <em><code class="parameter">persistent</code></em> parameter can be set to 
       <strong><code>DBX_PERSISTENT</code></strong>, if so, a persistent connection
       will be created.
      </p>
     </dd>

    
   </dl>

  </p>
  <p class="para">
   The <em><code class="parameter">host</code></em>, <em><code class="parameter">database</code></em>, 
   <em><code class="parameter">username</code></em> and <em><code class="parameter">password</code></em> 
   parameters are expected, but not always used depending on the connect
   functions for the abstracted module.
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.dbx-connect-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns an object on success, <strong><code>FALSE</code></strong> on error. If a connection has been
   made but the database could not be selected, the connection is closed and
   <strong><code>FALSE</code></strong> is returned. 
  </p>
  <p class="para">
   The returned <var class="varname"><var class="varname">object</var></var> has three properties:
   <dl>

    
     <dt>

      <span class="property">database</span>
     </dt>

     <dd>

      <span class="simpara">
       It is the name of the currently selected database. 
      </span>
     </dd>

    
    
     <dt>

      <span class="property">handle</span>
     </dt>

     <dd>

      <p class="para">
       It is a valid handle for the connected database, and as such it can be
       used in module-specific functions (if required).
       <div class="informalexample">
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dbx_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">DBX_MYSQL</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"db"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">mysql_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">handle</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;dbx_close($link)&nbsp;would&nbsp;be&nbsp;better&nbsp;here<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
        </div>

       </div>
      </p>
     </dd>

    
    
     <dt>

      <span class="property">module</span>
     </dt>

     <dd>

      <span class="simpara">
       It is used internally by dbx only, and is actually the module number
       mentioned above.
      </span>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 changelog" id="refsect1-function.dbx-connect-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.0.0</td>
       <td>
        Introduced <strong><code>DBX_SQLITE</code></strong>.
       </td>
      </tr>

      <tr>
       <td>4.3.0</td>
       <td>
        Introduced <strong><code>DBX_OCI8</code></strong>.
       </td>
      </tr>

      <tr>
       <td>4.2.0</td>
       <td>
        Introduced <strong><code>DBX_SYBASECT</code></strong>.
       </td>
      </tr>

      <tr>
       <td>4.1.0</td>
       <td>
        Introduced <strong><code>DBX_FBSQL</code></strong>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.dbx-connect-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-856">
    <p><strong>Example #1 <span class="function"><strong>dbx_connect()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dbx_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">DBX_ODBC</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"db"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">DBX_PERSISTENT</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Could&nbsp;not&nbsp;connect"</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"Connected&nbsp;successfully"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">dbx_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 notes" id="refsect1-function.dbx-connect-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Always refer to the module-specific documentation as well.
   </p>
  </p></blockquote>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.dbx-connect-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.dbx-close.html" class="function" rel="rdfs-seeAlso">dbx_close()</a> - Close an open connection/database</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.dbx-compare.html">dbx_compare</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.dbx-error.html">dbx_error</a></div>
 <div class="up"><a href="ref.dbx.html">dbx 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
